package com.csdj.t309.controller;

import com.csdj.t309.entity.TSysUser;
import com.csdj.t309.exception.T309Exception;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/test")
public class HelloController  {

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public ModelAndView hello(Model model){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("hello");
        modelAndView.addObject("name","cloud");
        return modelAndView;
    }

    @GetMapping("/helloworld")
    public ModelAndView helloworld(
            @RequestParam(value="name",required = true)String realname,
            @RequestParam int age){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("hello");
        modelAndView.addObject("name",realname);
        modelAndView.addObject("age",age);
        throw  new T309Exception("自己搞错了！");
//        return modelAndView;
    }
    @GetMapping("/input")
    public  String input(){
        return "input";
    }

    @PostMapping("/name")
    public String name(@RequestParam String name, Model model){
        model.addAttribute("name",name);
        return "hello";
    }

    @GetMapping("/user")
    @ResponseBody
    public TSysUser getUser(){
        TSysUser tSysUser = new TSysUser();
        tSysUser.setRealName("cloud");
        return tSysUser;
    }

}
